﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using agvcontroller.Common;
using agvcontroller.Control;
using agvcontroller.Process;
using agvcontroller.Common.DataBase;

namespace agvcontroller.GUI
{
    /// <summary>
    /// Interaction logic for UCVehicleViewer.xaml
    /// </summary>
    public partial class UCVehicleViewer : UserControl
    {
        CVehicle Vehicle;

        bool Initiailized = false;

        public UCVehicleViewer()
        {
            InitializeComponent();
        }

        public UCVehicleViewer(CVehicle vehicle)
        {
            InitializeComponent();

            Vehicle = vehicle;

            InitUI();
        }

        public void SetVehicle(CVehicle vehicle)
        {
            Vehicle = vehicle;

            InitUI();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // Do not load your data at design time.
            // if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            // {
            // 	//Load your data here and assign the result to the CollectionViewSource.
            // 	System.Windows.Data.CollectionViewSource myCollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["Resource Key for CollectionViewSource"];
            // 	myCollectionViewSource.Source = your data
            // }
        }

        void InitUI()
        {
            try
            {
                tbID.Text = Vehicle.ID.ToString();
                tbName.Text = Vehicle.Name;
                tbIP.Text = Vehicle.VehicleIP.ToString();
                tbPort.Text = Vehicle.Port.ToString();
                chkUse.IsChecked = Vehicle.Use;
                chkForward.IsChecked = Vehicle.CanForward;
                chkBackward.IsChecked = Vehicle.CanBackWard;
                chkRight.IsChecked = Vehicle.CanRight;
                chkLeft.IsChecked = Vehicle.CanLeft;
                chkSideRight.IsChecked = Vehicle.CanSideRight;
                chkSideLeft.IsChecked = Vehicle.CanSideLeft;

                //cmbGuideType = 
                cbCommType.Items.Clear();
                foreach (string type in CCommonInfo.CommType.CommTypeList)
                {
                    cbCommType.Items.Add(type);
                }
                cbCommType.SelectedValue = Vehicle.CommType;

                cbEjectType.Items.Clear();
                foreach (string type in CCommonInfo.EjectType.EjectTypeList)
                {
                    cbEjectType.Items.Add(type);
                }
                cbEjectType.SelectedValue = Vehicle.EjectType;

                cbGuideType.Items.Clear();
                foreach (string type in CCommonInfo.GuideType.GuideTypeList)
                {
                    cbGuideType.Items.Add(type);
                }
                cbGuideType.SelectedValue = Vehicle.GuideType;

                imgVehicle.Source = new BitmapImage(new Uri(string.Format(@"C:\{0}.jpg", Vehicle.EjectType)));

                Initiailized = true;
            }
            catch (Exception ex)
            {
            }

        }

        private void cbEjectType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!Initiailized) return;

            imgVehicle.Source = new BitmapImage(new Uri(string.Format(@"..\Images\{0}.jpg", cbEjectType.SelectedValue)));
        }
    }
}
